/****************************************************************************
**
** Copyright (C) 2011 Kimitake
** Contact: Kimitake (kimitake@gmail.com)
**
** This file is part of CuteUp application.
**
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General
** Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** This file is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without evene the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with this file. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/

import QtQuick 1.0
import "../meetup_ui" 1.0 as UI
import "." 1.0 as W

Item {
    id: screen

    property int screenWidth: 480
    property int screenHeight: 640

    property variant currentUI: startPage
    property variant nextUI: null
    property variant prevUI: null

    width: screenWidth
    height: screenHeight

    state: "startPage"

    function funcPrevPage() {
        console.log("prev");

        prevUI = currentUI.prev();
        if (prevUI == null) {
            console.log("prevUI is null");
            return;
        }

        nextUI = currentUI
        currentUI = prevUI

        screen.state = "currentPage"
        screen.state = "prevPage"
    }

    function funcNextPage() {
        console.log("next");

        nextUI = currentUI.next();
        if (nextUI == null)
            return;

        prevUI = currentUI;
        currentUI = nextUI;

        screen.state = "currentPage"
        screen.state = "nextPage"
    }

    Rectangle {
        id: base
        anchors.fill: parent
        color: "#000000"

        W.Bio {
            id: startPage
            x: parent.width * 1.5
            function prev() { return null; }
            function next() { return page0020; }
        }

        W.AboutCuteUp {
            id: page0020
            x: parent.width * 1.5
            function prev() { return startPage; }
            function next() { return page0030; }
        }

        W.FeatureLists {
            id: page0030
            x: parent.width * 1.5
            function prev() { return page0020; }
            function next() { return page0040; }
        }

        UI.MainWindow {
            id: page0040
            x: parent.width * 1.5
            function prev() { return page0030; }
            function next() { return page0050; }
        }

        W.WhatIsOAuth {
            id: page0050
            x: parent.width * 1.5
            function prev() { return page0040; }
            function next() { return page0060; }
        }

        UI.MainWindow {
            id: page0060
            x: parent.width * 1.5
            function prev() { return page0050; }
            function next() { return page0070; }
        }

        W.MeetupAPI {
            id: page0070
            x: parent.width * 1.5
            function prev() { return page0060; }
            function next() { return page0100; }
        }

        UI.MainWindow {
            id: page0100
            x: parent.width * 1.5
            function prev() { return page0070; }
            function next() { return page0800; }
        }

        W.MoreFeatures {
            id: page0800
            x: parent.width * 1.5
            function prev() { return page0100; }
            function next() { return page0900; }
        }

        W.ThankYou {
            id: page0900
            x: parent.width * 1.5
            function prev() { return page0800; }
            function next() { return null; }
        }

        // prev / next button
        W.PrevNextButtons {
            anchors.bottom: parent.bottom
            anchors.left: parent.left
            width: parent.width
            onPrevPage: { funcPrevPage(); }
            onNextPage: { funcNextPage(); }
        }
    }

	states: [
		State {
			name: "currentPage"
		},
		State {
			name: "startPage"
			PropertyChanges {
				target: startPage
				x: 0
			}
		},
		State {
			name: "nextPage"
			PropertyChanges {
				target: prevUI
				x: parent.width * 1.5
			}
			PropertyChanges {
				target: nextUI
				x: 0
			}
		},
		State {
			name: "prevPage"
			PropertyChanges {
				target: nextUI
				x: parent.width * 1.5
			}
			PropertyChanges {
				target: prevUI
				x: 0
			}
		}
	]
	transitions: [
		Transition {
			NumberAnimation {
				properties: "x,y,opacity";
				duration: 200
			}
		}
	]
}
